import { usePlayerStore, type KeywordCodeType } from "@/stores/player";
import { onMounted, onUnmounted } from "vue";

export function usePlayerMove() {
  const { operations } = usePlayerStore();
  const keywordEvent = (e: KeyboardEvent) => {
    const operationKey = e.code as KeywordCodeType;
    operations[operationKey]?.();
  };

  onMounted(() => {
    window.addEventListener("keyup", keywordEvent);
  });

  onUnmounted(() => {
    window.removeEventListener("keyup", keywordEvent);
  });
}
